﻿<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Negocios
 *
 * @author marcelo.diaz
 */
//class Negocios extends Template_controller{
class Negocios extends Controller{

  function Negocios(){
    parent::Controller("negocios");
    $this->load->model("Negocios_Model");
  }

	function index()
	{
      $email = "ALL";
      $this->email->from('conocepunta@gmail.com');
      $this->email->to('conocepunta@gmail.com');
      $this->email->subject('Negocios access');
      
      $data['page_title'] = "Negocios en Punta Alta - Ropa - Indumentaria - Farmacias - Computaci&oacute;n - Automotores";
      $data['meta_description'] = '<meta name="description" content="ConocePunta - Punta Alta, Buenos Aires, Argentina - Negocios en Punta Alta - Ropa - Indumentaria - Farmacias - Computaci&oacute;n - Automotores" />';      
      $output = $this->load->view('head_view', $data, true);
      
      $places = $this->Negocios_Model->_all();
      $navbar = $this->write_navbar();
      //iterate and parse places
      $output .= $navbar;
      $output .= "<div class='content centered'>";
      $output .= 	$this->write_custom_content($places);  
      $output .= 	$this->write_sidebar("ropa farmacias computacion automotores");
      $output .= "</div>";
      //---------MAP---------
      $output .= $this->write_map();      
      $output .= $this->load->view('foot_view', "", true);
      $this->output->set_output($output);
      $this->email->message($email);
      //$this->email->send();
    }

    function name($place){
      $json = $this->Negocios_Model->get_place($place);
      header('Content-Type:application/json');
      echo json_encode($json);	  
    }

    function all(){
      $json = $this->Negocios_Model->get_all();
      header('Content-Type:application/json');
      //!!!
      echo json_encode($json); 
    }

    function nombre($name = false){
      if ($name){
        $email = "[".$name."]";
        $this->email->from('conocepunta@gmail.com');
        $this->email->to('conocepunta@gmail.com');
        $this->email->subject('[Negocios] access');        
        
        $name_replaced = str_replace("-", " ", $name);
        $navbar = $this->write_navbar();
        $data['page_title'] = $name_replaced." - Negocios en Punta Alta - Ropa - Indumentaria - Farmacias - Computaci&oacute;n - Automotores";
        $data['meta_description'] = '<meta name="description" content="'.$name_replaced.' - ConocePunta - Punta Alta, Buenos Aires, Argentina - Negocios en Punta Alta - Ropa - Indumentaria - Farmacias - Computaci&oacute;n - Automotores" />';        
        $output = $this->load->view('head_view', $data, true);        
        
        $banner_adsense = '<div class="lheader"><script type="text/javascript"><!--
                                      google_ad_client = "pub-2113662635661393";
                                      
                                      google_ad_slot = "4418063429";
                                      google_ad_width = 728;
                                      google_ad_height = 90;
                                      //-->
                                      </script>
                                      <script type="text/javascript"
                                      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                                      </script></div>';
        
        $output .= $navbar.
                   "<div class='content slim-content centered' style='height:120px'>".
        				$banner_adsense.
                   "</div>";        
        
        $content = "";
        //$place = $this->Negocios_Model->_place(strtolower($name));
		$place = $this->Negocios_Model->get_place($name);
        if (!$place){          
          $places = $this->Negocios_Model->_all();
          //iterate and parse places
	      $content .= "<div class='content centered'>".
	 	      			"<p class='ui-state-highlight' style='width:50%; padding:10px; text-align:center;'>No hemos podido encontrar <strong>$name</strong>.</p>";
	      $content .= 	$this->write_custom_content($places);  
	      $content .= 	$this->write_sidebar("recitales fiestas boliches discos eventos");
	      $content .= "</div>";        	 
          $email .= "NOT FOUND";
        } else{
          //parse place
          $content .= "<div class='content slim-content centered'>".
          				$this->write_specific_item($place).
          			  "</div>";
        }
        $output .= $content;
        			            
        $output .= $this->load->view('foot_view', "", true);
        $this->output->set_output($output);
        //$this->email->message($email);
        //$this->email->send();
      }else{
        $this->index();	
      }
    }
    
    function write_specific_item($marker){
    	$content = "";
    	$marker_name = str_replace("-", " ", $marker['name']);
    	$url  = "www.conocepunta.com.ar/".$this->get_controller_name()."/nombre/".$marker['name'];
        	
    	//social widgets---------------------
    	$fb   = "<div class='fb_like'><iframe src='http://www.facebook.com/plugins/like.php?href=".$url."&amp;layout=button_count&amp;show-faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;locale=es_LA' frameborder='0' scrolling='no' style='vertical-align: middle; border: medium none; overflow: hidden; width: 100px; height: 21px;' allowtransparency='true'></iframe></div>";
    	$addthis = '<div class="addthis_toolbox fb_like">'.
    			'<div class="hover_effect">'.
    			'<div style="display:inline-block"><a class="addthis_button_twitter"'.
    			'addthis:url="http://'.$url.'"'.
    			'addthis:title="'.$marker_name.' en '.$marker["address"].' #'.str_replace(" ","", $marker["city"]).' @conocepunta">&nbsp;</a></div>'.
    			'<div style="display:inline-block"><a class="addthis_button_google"'.
    			'addthis:url="http://'.$url.'"'.
    			'addthis:title="'.$marker_name.': '.$marker["address"].' @conocepunta">&nbsp;</a></div>'.
    			'<div style="display:inline-block"><a class="addthis_button_expanded">&nbsp;&nbsp;Mas</a></div>'.
    			'<div style="clear:both; float:none;"></div>'.
    			'</div>'.
    			'</div>';
    	//$gplusbutton = '<g:plusone size="small" href="http://'.$url.'"></g:plusone>';
    		
    	$social = "<div>".$fb.$addthis."</div>";
    	//--------------------------------
    
    	//$image = "<figure><img alt='".$marker_name."' class='lheader' src='".$marker['img']."'></figure>";
    	//---------------static map
    	//$image = "<figure><img alt='".$marker_name."' class='lheader' src='http://maps.google.com/staticmap?center=".$marker['lat'].",".$marker['lng']."&zoom=15&size=225x225&maptype=satellite&&markers=icon:".$marker['icon']."%7C".$marker['lat'].",".$marker['lng']."&key=ABQIAAAALyKwFZzMQBTWU3CUmBrN7RTvufBQ4WA-npmjEqhq0GDcUkCFMRTabPeW_m0vIN3Bghd4m7Mv_m-mOQ'></figure>".
    	$image = "<figure><img alt='".$marker_name."' class='lheader' src='http://maps.google.com/staticmap?center=".$marker['lat'].",".$marker['lng']."&zoom=15&size=225x225&maptype=satellite&&markers=".$marker['lat'].",".$marker['lng']."&key=ABQIAAAALyKwFZzMQBTWU3CUmBrN7RTvufBQ4WA-npmjEqhq0GDcUkCFMRTabPeW_m0vIN3Bghd4m7Mv_m-mOQ'></figure>";
    	//-------------------------
    
    	$desc = "<p>".$marker['description']."</p>";
    	//$screen = "<div class='screenshot vintage lheader' style='margin-bottom:7px'>".
    	$screen = "<div class='vintage lheader' style='margin-bottom:7px'>".$image."</div>".
    			  "<div class='figcaption'>".
	    			//str_pad(substr($marker_name,0,15),18,"...").
    				//$marker_name.
    				"<p>".$marker['address']."</p>".
    				"<p class='place'>".$marker['city']."</p>".
    			  "</div>".
    			  $social;
    	//----------------------------------------------------------------------
    	//loading related data
    	$related = "<ul>";
    	foreach ($marker['related'] as $k => $rel){
    		$clean_name = str_replace("-", " ", $rel['name']);
    		$related .= "<li class='box mini-post figcaption'>
    		<figure><img class='small' title='".$clean_name."' alt='".$clean_name."' src='".$rel['img']."'></figure>
    		<a href='".base_url().$this->category_string($rel['marker_cat'])."/nombre/".$rel['name']."' target='_new'>".$clean_name."</a>
    		</li>";
    	}
    	$related .= "</ul>";
    
    	//-------------------------------------------------------------------------
    	//--ADMINISTRAR SECTION
    	$administrar = "";
    	//si no tiene row en socio-marker ==> mostrar span con redireccion a /socios
    	$query = $this->db->query("SELECT *
    			FROM marker as m
    			LEFT outer join socio_marker as rel
    			on m.id_marker=rel.id_marker
    			WHERE rel.id_marker IS NULL and
    			m.id_marker = ".$marker['id_marker']
    	);
    	$marker_asociado = $query->row_array();
    	if(!empty($marker_asociado)){
    		$attributes = array('class' => ' rheader ');
    		$administrar .= form_open('socios', $attributes).
    		form_hidden('id_marker',$marker['id_marker']).
    		form_hidden('marker_name',$marker['name']).
    		form_submit('submit', 'Administrar', 'class="submit manage" title="Es tu Negocio?"').
    		form_close();
    	}
    	//---------------------------------------------------------------------------
    	$content =  "<div class='brief box post'>".
				    	//title
				    	"<div>".
				    		"<h1 class='inline'><p>".$marker_name."</p></h1>".
				    		$administrar.
				    	"</div>".
				    	"<p class='separator'></p>".
				    	"<article id='".$marker['name']."' class='inline box post lheader'>".
				    		$screen.
				    	"</article>".
				    	"<article class='inline' style='padding-left: 20px; max-width: 500px;'>".
					    	"<div>".$desc."</div>".
				    	"</article>".
				    	//"<p class='separator'></p>".
				    	"<article class='inline figcaption' style='width:100%'>".
				    		"<p class='separator'></p>".
				    		"<p class='place' style='text-align:left; padding-bottom:10px'>Entradas relacionadas...</p>".
				    		$related.
				    	"</article>".
			    	"</div>";
    	return $content;
    }    
}
?>
